'use strict';

var gulp = require('gulp');
var rev = require('gulp-rev');
var gulpif = require('gulp-if');
var imagemin = require('gulp-imagemin');
var sourcemaps = require('gulp-sourcemaps');
var events = require('events').EventEmitter.defaultMaxListeners = Infinity;
var config = require('../config');
var env = require('../utils/env');
var handleErrors = require('../utils/handleErrors');

// image压缩
gulp.task('images', function() {
    return gulp.src(config.images.src).pipe(gulpif(env() === 'development', sourcemaps.init())).pipe(imagemin()).pipe(rev()).pipe(gulp.dest(config.images.dest)).pipe(gulpif(env() === 'development', sourcemaps.write('.', {includeContent: false}))).pipe(gulpif(env() === 'development', gulp.dest(config.images.dest))).pipe(rev.manifest()).on('error', handleErrors).pipe(gulp.dest(config.images.dest));
});
